/*   1:    */ package com.atomikos.datasource.xa.session;
/*   2:    */ 
/*   3:    */ import com.atomikos.datasource.xa.XAResourceTransaction;
/*   4:    */ import com.atomikos.datasource.xa.XATransactionalResource;
/*   5:    */ import com.atomikos.icatch.CompositeTransaction;
/*   6:    */ import com.atomikos.icatch.HeuristicMessage;
/*   7:    */ import com.atomikos.icatch.system.Configuration;
/*   8:    */ import javax.transaction.xa.XAException;
/*   9:    */ import javax.transaction.xa.XAResource;
/*  10:    */ 
/*  11:    */ class BranchEnlistedStateHandler
/*  12:    */   extends TransactionContextStateHandler
/*  13:    */ {
/*  14:    */   private CompositeTransaction ct;
/*  15:    */   private XAResourceTransaction branch;
/*  16:    */   
/*  17:    */   BranchEnlistedStateHandler(XATransactionalResource resource, CompositeTransaction ct, XAResource xaResource, HeuristicMessage hmsg)
/*  18:    */   {
/*  19: 52 */     super(resource, xaResource);
/*  20: 53 */     this.ct = ct;
/*  21: 54 */     this.branch = ((XAResourceTransaction)resource.getResourceTransaction(ct));
/*  22: 55 */     this.branch.setXAResource(xaResource);
/*  23: 56 */     if (hmsg != null) {
/*  24: 56 */       this.branch.addHeuristicMessage(hmsg);
/*  25:    */     }
/*  26: 57 */     this.branch.resume();
/*  27:    */   }
/*  28:    */   
/*  29:    */   public BranchEnlistedStateHandler(XATransactionalResource resource, CompositeTransaction ct, XAResource xaResource, XAResourceTransaction branch)
/*  30:    */     throws InvalidSessionHandleStateException
/*  31:    */   {
/*  32: 64 */     super(resource, xaResource);
/*  33: 65 */     this.ct = ct;
/*  34: 66 */     this.branch = branch;
/*  35: 67 */     branch.setXAResource(xaResource);
/*  36:    */     try
/*  37:    */     {
/*  38: 69 */       branch.xaResume();
/*  39:    */     }
/*  40:    */     catch (XAException e)
/*  41:    */     {
/*  42: 71 */       String msg = "Failed to resume branch: " + branch;
/*  43: 72 */       throw new InvalidSessionHandleStateException(msg);
/*  44:    */     }
/*  45:    */   }
/*  46:    */   
/*  47:    */   TransactionContextStateHandler checkEnlistBeforeUse(CompositeTransaction currentTx, HeuristicMessage hmsg)
/*  48:    */     throws InvalidSessionHandleStateException, UnexpectedTransactionContextException
/*  49:    */   {
/*  50: 80 */     if ((currentTx == null) || (!currentTx.isSameTransaction(this.ct)))
/*  51:    */     {
/*  52: 85 */       String msg = "The connection/session object is already enlisted in a (different) transaction.";
/*  53: 86 */       if (Configuration.isDebugLoggingEnabled()) {
/*  54: 86 */         Configuration.logDebug(msg);
/*  55:    */       }
/*  56: 87 */       throw new UnexpectedTransactionContextException();
/*  57:    */     }
/*  58: 91 */     return null;
/*  59:    */   }
/*  60:    */   
/*  61:    */   TransactionContextStateHandler sessionClosed()
/*  62:    */   {
/*  63: 96 */     return new BranchEndedStateHandler(getXATransactionalResource(), this.branch, this.ct);
/*  64:    */   }
/*  65:    */   
/*  66:    */   TransactionContextStateHandler transactionTerminated(CompositeTransaction tx)
/*  67:    */   {
/*  68:102 */     TransactionContextStateHandler ret = null;
/*  69:103 */     if (this.ct.isSameTransaction(tx)) {
/*  70:103 */       ret = new NotInBranchStateHandler(getXATransactionalResource(), getXAResource());
/*  71:    */     }
/*  72:104 */     return ret;
/*  73:    */   }
/*  74:    */   
/*  75:    */   public TransactionContextStateHandler transactionSuspended()
/*  76:    */     throws InvalidSessionHandleStateException
/*  77:    */   {
/*  78:    */     try
/*  79:    */     {
/*  80:111 */       this.branch.xaSuspend();
/*  81:    */     }
/*  82:    */     catch (XAException e)
/*  83:    */     {
/*  84:113 */       Configuration.logWarning("Error in suspending transaction context for transaction: " + this.ct, e);
/*  85:114 */       String msg = "Failed to suspend branch: " + this.branch;
/*  86:115 */       throw new InvalidSessionHandleStateException(msg, e);
/*  87:    */     }
/*  88:117 */     return new BranchSuspendedStateHandler(getXATransactionalResource(), this.branch, this.ct, getXAResource());
/*  89:    */   }
/*  90:    */   
/*  91:    */   boolean isInTransaction(CompositeTransaction tx)
/*  92:    */   {
/*  93:122 */     return this.ct.isSameTransaction(tx);
/*  94:    */   }
/*  95:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\transactions-jta\3.7.0\transactions-jta-3.7.0.jar
 * Qualified Name:     com.atomikos.datasource.xa.session.BranchEnlistedStateHandler
 * JD-Core Version:    0.7.0.1
 */